package com.catmiw.wyz;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import com.catmiw.wyz.util.ExcelUtils;

public class TestForegroudColor {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Workbook wb=new HSSFWorkbook();
		Sheet sheet=wb.createSheet();
		
		CellStyle style=wb.createCellStyle();
		Font font = wb.createFont();
		font.setFontName("微软雅黑");
		font.setFontHeightInPoints((short) 10);
		
		style.setFont(font);
		style.setBorderBottom(CellStyle.BORDER_THIN);
		style.setBorderLeft(CellStyle.BORDER_THIN);
		style.setBorderRight(CellStyle.BORDER_THIN);
		style.setBorderTop(CellStyle.BORDER_THIN);
		
		int rowcount=0;
		for (int i=0;i<10;i++){
			sheet.setColumnWidth(i, sheet.getColumnWidth(i)*2);
		}
		for (IndexedColors ic:IndexedColors.values()){
			CellStyle cs=wb.createCellStyle();
			cs.cloneStyleFrom(style);
			cs.setFillForegroundColor(ic.getIndex());
			cs.setFillPattern(CellStyle.SOLID_FOREGROUND);
			Row row=sheet.createRow(rowcount++);
			row.setHeight((short)(row.getHeight()*2));
			for (int i=0;i<10;i++){
				Cell cell=row.createCell(i);
				cell.setCellValue(ic.name());
				cell.setCellStyle(cs);
			}
		}

		ExcelUtils.writeWorkbook(wb, "e:\\test.xls");
	}

}
